package com.abcd.kaixin.connect;

import org.springframework.social.connect.ApiAdapter;
import org.springframework.social.connect.ConnectionValues;
import org.springframework.social.connect.UserProfile;
import org.springframework.social.connect.UserProfileBuilder;
import com.abcd.kaixin.api.Kaixin;
import com.abcd.kaixin.api.impl.User;

public class KaixinAdapter implements ApiAdapter<Kaixin> {

	@Override
	public UserProfile fetchUserProfile(Kaixin kaixin) {
		User user = kaixin.friendOperations().getMyInfo(null);
		return new UserProfileBuilder().setName(user.getName()).setUsername(user.getCity()).build();
	}

	@Override
	public void setConnectionValues(Kaixin kaixin, ConnectionValues values) {
		User user = kaixin.friendOperations().getMyInfo(null);
		values.setProviderUserId(String.valueOf(user.getUid()));
		values.setDisplayName(user.getName());
		values.setProfileUrl("http://www.kaixin001.com/home/?uid=" + user.getUid());
		values.setImageUrl(user.getLogo120());
		
	}

	@Override
	public boolean test(Kaixin kaixin) {
		try {
			kaixin.friendOperations().getMyInfo(null);
		}catch (Exception e) {
			return false;
		}
		return true;
	}

	@Override
	public void updateStatus(Kaixin arg0, String arg1) {
		
	}

}
